package com.youme.section.profile

import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.net.Uri
import android.util.Log
import android.view.View
import com.hyphenate.easeim.R
import com.salton123.ui.base.YoumeTitleActivity
import com.salton123.utils.ImageLoaders
import com.youme.mCurrentUserProfile
import com.zhihu.matisse.Matisse
import com.zhihu.matisse.MimeType
import com.zhihu.matisse.engine.impl.GlideEngine
import kotlinx.android.synthetic.main.fragment_profile_detail.*

/**
 * Time:4/18/21 5:02 PM
 * Author:
 * Description:
 */
class ProfileDetailActivity : YoumeTitleActivity() {
    override fun getLayoutId(): Int = R.layout.fragment_profile_detail

    companion object {
        const val REQUEST_CODE_CHOOSE = 100
    }

    override fun initViewAndData() {
        ImageLoaders.loadCircleCrop(ivAvatar, mCurrentUserProfile?.avatar ?: "")
        sbUserId.rightText = "${mCurrentUserProfile?.userId}"
        sbUserNick.rightText = "${mCurrentUserProfile?.nickName}"
    }

    override fun initListener() {
        super.initListener()
        setListener(flAvatar)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v) {
            flAvatar -> {
                Matisse.from(this@ProfileDetailActivity)
                    .choose(MimeType.ofImage())
                    .countable(true)
                    .maxSelectable(1)
                    .gridExpectedSize(4)
                    .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                    .thumbnailScale(0.85f)
                    .imageEngine(GlideEngine())
                    .showPreview(false)
                    .forResult(REQUEST_CODE_CHOOSE)
            }
        }
    }

    var mSelected: List<Uri>? = null

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_CHOOSE && resultCode == Activity.RESULT_OK) {
            mSelected = Matisse.obtainResult(data)
            Log.d("Matisse", "mSelected: $mSelected")
        }
    }
}